package com.annhoa.system.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.annhoa.core.web.BaseController;
import com.annhoa.security.service.AuthService;
import com.annhoa.util.PageData;

/**
 * 
 * @author annhoa <if>thy 模板 需要开启thy配置</if>
 *
 */
@Controller
public class ThymeleafController extends BaseController {

	@Autowired
	private AuthService authService;

	@RequestMapping(value = "/login")
	public String login() {
		return "/system/demo/thy-login";
	}

	@RequestMapping(value = "/")
	public String indexs(ModelMap mm) {
		PageData pageData = this.getPageData();
		pageData.put("title", "你好，thymeleaf模板！");
		pageData.put("content", "我曾经跨过山大海，也穿过人潮和人海，我曾经拥有这所有一切，都随风烟消云散！");
		pageData.put("extraInfo", "再见不送");
		mm.addAttribute(pageData);
		return "/system/demo/thy-index";
	}

	@RequestMapping(value = "/thymeleaf")
	public String thymeleaf(ModelMap mm) {
		return "/system/demo/thy-tag";
	}

	@RequestMapping(value = "/thymeleaf/login")
	public ModelAndView loginPage() throws AuthenticationException {
		ModelAndView mv = this.getModelAndView();
		PageData pd = this.getPageData();
		pd = (PageData) authService.loginPage(pd);
		mv.addObject("pd", pd);
		mv.setViewName("/system/demo/thy-logsuccess");
		return mv;
	}

}
